package com.terrence.sso.token.server.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.terrence.sso.token.server.Config;
import com.terrence.sso.token.server.service.SidCacheService;
import com.terrence.sso.token.server.service.SidCookieService;

public class SSOLogoutServlet extends HttpServlet {
    private static final long serialVersionUID = -3170191388656385924L;

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //清理sid信息(Cookie与缓存)
    	String sid = SidCookieService.getSid(request);
    	SidCacheService.clear(sid);
    	//并重定向到登录页面
    	response.sendRedirect(Config.SSO_SERVER_LOGIN);
    }

}